import Mock from 'mockjs';

Mock.mock('/api/test', 'get' , (options => {
  return Mock.mock({
    message: 'mock success'
  })
}))

Mock.mock('/api/loadmore', 'post', (options: any) => {
  const { offset, limit } =  JSON.parse(options.body);
  const data = Mock.mock({
    [`list|${limit}`]: [
      {
        'id|+1': offset + 1,
        name: '@cname',
        'age|18-60': 1,
        'gender|1': ['男', '女'],
      },
    ],
  });
  return Mock.mock(data);
});

Mock.mock('/api/getOptions1', 'post', (options ) => {
  return Mock.mock({
    'options|3': [
      {
        'id|+1': 1,
        'name|+1': ['Option 1', 'Option 2', 'Option 3'],
      },
    ],
  })
});

Mock.mock('/api/getOptions2', 'post', (data) => {
  const { id } =  JSON.parse(data.body);
  const options = [
    { id: 1, name: 'Sub Option 1' },
    { id: 1, name: 'Sub Option 2' },
    { id: 1, name: 'Sub Option 3' },
    { id: 2, name: 'Sub Option 4' },
    { id: 2, name: 'Sub Option 5' },
    { id: 3, name: 'Sub Option 6' },
  ];
  return options.filter((option) => option.id === id);
});
